<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">


  <title>手摸手教你写 Kubernetes 的 golang 服务-blog.qikqiak.com|阳明的博客|Kubernetes|Docker|Python|Golang|Cloud Native</title>
  <meta property="og:title" content="手摸手教你写 Kubernetes 的 golang 服务" />
  <meta name="twitter:title" content="手摸手教你写 Kubernetes 的 golang 服务" />

  <meta name="description" content="我们前面介绍了很多关于kubernetes本身的操作，但是对于如何写一个完整的kubernetes应用还没有介绍过。在这篇文章中我们将介绍如何一步一步的写一个kubernetes的golang服务。

">
  <meta property="og:description" content="我们前面介绍了很多关于kubernetes本身的操作，但是对于如何写一个完整的kubernetes应用还没有介绍过。在这篇文章中我们将介绍如何一步一步的写一个kubernetes的golang服务。

">
  <meta name="twitter:description" content="我们前面介绍了很多关于kubernetes本身的操作，但是对于如何写一个完整的kubernetes应用还没有介绍过。在这篇文章中我们将介绍如何一步一步的写一个kubernetes的golang服务。

">
  <meta name="author" content=""/>
  <link href='https://blog.qikqiak.com/img/favicon.ico' rel='icon' type='image/x-icon'/>
  <meta property="og:image" content="https://blog.qikqiak.com/img/avatar.jpeg" />
  <meta name="twitter:image" content="https://blog.qikqiak.com/img/avatar.jpeg" />
  <meta name="twitter:card" content="summary" />
  <meta property="og:url" content="https://blog.qikqiak.com/post/write-kubernets-golang-service-step-by-step/" />
  <meta property="og:type" content="website" />
  <meta property="og:site_name" content="阳明的博客" />

  <meta name="generator" content="Hugo 0.34" />
  <link rel="canonical" href="https://blog.qikqiak.com/post/write-kubernets-golang-service-step-by-step/" />
  <link rel="alternate" href="https://blog.qikqiak.com/index.xml" type="application/rss+xml" title="阳明的博客">
  <link href="https://cdn.bootcss.com/KaTeX/0.7.1/katex.min.css" rel="stylesheet">
  <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/main.css?t=1235" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" />
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/pygment_highlights.css" />
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/highlight.min.css" />
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/prism.css?t=123" />
  <link rel="stylesheet" href="https://blog.qikqiak.com/css/search.css" />
<meta name="keywords" content="kubernetes, docker, golang, 服务">
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?970de9920f6089c287a7fd366138d4e9";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();
</script>



<link href="https://cdn.bootcss.com/photoswipe/4.1.1/photoswipe.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/photoswipe/4.1.1/default-skin/default-skin.min.css" rel="stylesheet">



<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

<div class="pswp__bg"></div>

<div class="pswp__scroll-wrap">
    
    <div class="pswp__container">
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
    </div>
    
    <div class="pswp__ui pswp__ui--hidden">
    <div class="pswp__top-bar">
      
      <div class="pswp__counter"></div>
      <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
      <button class="pswp__button pswp__button--share" title="Share"></button>
      <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
      <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
      
      
      <div class="pswp__preloader">
        <div class="pswp__preloader__icn">
          <div class="pswp__preloader__cut">
            <div class="pswp__preloader__donut"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
      <div class="pswp__share-tooltip"></div>
    </div>
    <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
    </button>
    <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
    </button>
    <div class="pswp__caption">
      <div class="pswp__caption__center"></div>
    </div>
    </div>
    </div>
</div>

<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-69668147-3', 'auto');
ga('send', 'pageview');
</script>
<script async src='//www.google-analytics.com/analytics.js'></script>

</head>

  <body>
    <nav class="navbar navbar-default navbar-fixed-top navbar-custom">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="https://blog.qikqiak.com/">阳明的博客</a>
    </div>

    <div class="collapse navbar-collapse" id="main-navbar">
      <ul class="nav navbar-nav navbar-right">
        
          
            <li>
              <a title="Home" href="https://ydzs.io">Home</a>
            </li>
          
        
          
            <li class="navlinks-container">
              <a class="navlinks-parent" href="javascript:void(0)">Categories</a>
              <div class="navlinks-children">
                
                  <a href="https://blog.qikqiak.com/page/archive/">Archive</a>
                
                  <a href="https://blog.qikqiak.com/tags">tags</a>
                
                  <a href="https://blog.qikqiak.com/tags/kubernetes">kubernetes</a>
                
                  <a href="https://blog.qikqiak.com/tags/python">python</a>
                
                  <a href="https://blog.qikqiak.com/tags/django">django</a>
                
                  <a href="https://blog.qikqiak.com/tags/ops">devops</a>
                
              </div>
            </li>
          
        
          
            <li class="navlinks-container">
              <a class="navlinks-parent" href="javascript:void(0)">海马学院</a>
              <div class="navlinks-children">
                
                  <a href="https://www.haimaxy.com/course/6y02wp/?utm_source=blog&amp;utm_campaign=referral&amp;utm_medium=topmenu">Python微服务实战</a>
                
                  <a href="https://www.haimaxy.com/course/pww13p/?utm_source=blog&amp;utm_campaign=referral&amp;utm_medium=topmenu">Webpack3.x 入门</a>
                
                  <a href="https://www.haimaxy.com/course/pjrqxm/?utm_source=blog&amp;utm_campaign=referral&amp;utm_medium=topmenu">Kubernetes 集群搭建</a>
                
              </div>
            </li>
          
        
          
            <li>
              <a title="About" href="https://blog.qikqiak.com/page/about/">About</a>
            </li>
          
        

        

        

        
          <li>
            <a href="#modalSearch" data-toggle="modal" data-target="#modalSearch" style="outline: none;">
              <span class="hidden-sm hidden-md hidden-lg">Search</span> <span id="searchGlyph" class="glyphicon glyphicon-search"></span>
            </a>
          </li>
          

      </ul>
    </div>

    <div class="avatar-container">
      <div class="avatar-img-border">
        
          <a title="阳明的博客" href="https://blog.qikqiak.com/">
            <img class="avatar-img" src="https://blog.qikqiak.com/img/avatar.jpeg" alt="阳明的博客" />
          </a>
        
      </div>
    </div>

  </div>
</nav>





  <div id="modalSearch" class="modal fade" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Search blog.qikqiak.com</h4>
        </div>
        <div class="modal-body">
            
<div class="aa-input-container" id="aa-input-container">
    <input type="search" id="aa-search-input" class="aa-input-search" placeholder="Search for titles or URIs..." name="search" autocomplete="off" />
    <svg class="aa-input-icon" viewBox="654 -372 1664 1664">
        <path d="M1806,332c0-123.3-43.8-228.8-131.5-316.5C1586.8-72.2,1481.3-116,1358-116s-228.8,43.8-316.5,131.5  C953.8,103.2,910,208.7,910,332s43.8,228.8,131.5,316.5C1129.2,736.2,1234.7,780,1358,780s228.8-43.8,316.5-131.5  C1762.2,560.8,1806,455.3,1806,332z M2318,1164c0,34.7-12.7,64.7-38,90s-55.3,38-90,38c-36,0-66-12.7-90-38l-343-342  c-119.3,82.7-252.3,124-399,124c-95.3,0-186.5-18.5-273.5-55.5s-162-87-225-150s-113-138-150-225S654,427.3,654,332  s18.5-186.5,55.5-273.5s87-162,150-225s138-113,225-150S1262.7-372,1358-372s186.5,18.5,273.5,55.5s162,87,225,150s113,138,150,225  S2062,236.7,2062,332c0,146.7-41.3,279.7-124,399l343,343C2305.7,1098.7,2318,1128.7,2318,1164z" />
    </svg>
</div>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/algoliasearch.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/autocomplete.min.js"></script>

<script>
var client = algoliasearch("1JDRAS0AZR", "8804ac109158bb3bb60d74ce98fa332f");
var index = client.initIndex('prod_blog');

autocomplete('#aa-search-input',
{ hint: false}, {
    source: autocomplete.sources.hits(index, {hitsPerPage: 5}),
    
    displayKey: 'name',
    
    templates: {
        
        suggestion: function(suggestion) {
            return '<span>' + '<a href="https://blog.qikqiak.com/post/' + suggestion.slug + '">' +
            suggestion._highlightResult.title.value + '</a></span>';
        }
    }
});
</script>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">close</button>
        </div>
      </div>
    </div>
  </div>

    
  
  
  




  
    <div id="header-big-imgs" data-num-img=1 data-img-src-1="https://blog.qikqiak.com/img/posts/photo-1508922450598-2f5b1193950a.jpeg" data-img-desc-1="Lake Wakatipu, New Zealand"></div>
  

  <header class="header-section has-img">
    
      <div class="intro-header big-img">
        
        <div class="container">
          <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
              <div class="post-heading">
                <h1>手摸手教你写 Kubernetes 的 golang 服务</h1>
                  
                  
                    <span class="post-meta">
  Posted on February 8, 2018
  
</span>


                  
              </div>
            </div>
          </div>
        </div>
        <span class="img-desc" style="display: inline;"></span>
      </div>
    
    <div class="intro-header no-img">
      
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
            <div class="post-heading">
              <h1>手摸手教你写 Kubernetes 的 golang 服务</h1>
                
                
                  <span class="post-meta">
  Posted on February 8, 2018
  
</span>


                
            </div>
          </div>
        </div>
      </div>
    </div>
  </header>


    
<div class="container" role="main">
  <div class="row">
    <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">

      <div>
          
          
          <h5 id="tags" style="margin-top: 0px;">标签:
            
                <a href="https://blog.qikqiak.com/tags/kubernetes/">kubernetes</a> &nbsp;
            
                <a href="https://blog.qikqiak.com/tags/docker/">docker</a> &nbsp;
            
                <a href="https://blog.qikqiak.com/tags/golang/">golang</a> &nbsp;
            
          </h5>
          
      </div>

      <article role="main" class="blog-post">
        <p>我们前面介绍了很多关于<code>kubernetes</code>本身的操作，但是对于如何写一个完整的<code>kubernetes</code>应用还没有介绍过。在这篇文章中我们将介绍如何一步一步的写一个<code>kubernetes</code>的<code>golang</code>服务。</p>

<p></p>

<h2 id="golang">golang</h2>

<p>对于 golang 的安装和配置，我们这里就不详细说明了，因为这也不是我们的重点，我相信这一步你是能够自己独立完成的。</p>

<blockquote>
<p>一个令人比较兴奋的事情是现在国内用户访问<code>golang</code>网站可以不用梯子了，我们可以自由的访问<a href="https://golang.google.cn/">https://golang.google.cn/</a>网站了。</p>
</blockquote>

<p>新建项目文件夹<strong>goappk8s</strong>，然后在该目录下面新建一个<strong>src</strong>目录</p>

<pre><code class="language-shell">$ mkdir goappk8s &amp;&amp; cd goappk8s
$ mkdir src
</code></pre>

<p>在<strong>goappk8s</strong>目录下新建一个设置<code>GOPATH</code>的脚本：(<code>setup-gopath.sh</code>)</p>

<pre><code class="language-bash">#!/bin/bash
DIR=&quot;$(cd &quot;$(dirname &quot;${BASH_SOURCE[0]}&quot;)&quot; &amp;&amp; pwd)&quot;
export GOPATH=&quot;$DIR&quot;
</code></pre>

<p>然后我们执行上面的脚本，设置<code>GOPATH</code>为当前工程目录：</p>

<pre><code class="language-shell">$ source setup-gopath.sh
$ echo $GOPATH
/Users/ych/devs/workspace/yidianzhishi/goappk8s
</code></pre>

<p>我们可以看到<code>GOPATH</code>已经设置为当前项目根目录了。然后在<strong>src</strong>目录下面添加 golang 代码：</p>

<pre><code class="language-shell">$ mkdir -p github.com/cnych/goappk8s &amp;&amp; cd github.com/cnych/goappk8s
$ touch main.go
</code></pre>

<p>我们添加一个最简单的<code>golang</code>服务，提供了一个 ping 接口：</p>

<pre><code class="language-golang">package main

import (
    &quot;github.com/gin-gonic/gin&quot;
    &quot;net/http&quot;
)

func main() {
    router := gin.Default()
    router.GET(&quot;/ping&quot;, func(c *gin.Context) {
        c.String(http.StatusOK, &quot;PONG&quot;)
    })
    router.Run(&quot;:8080&quot;)
}
</code></pre>

<p>我们可以看到上面的服务中依赖了一个第三方包<code>github.com/gin-gonic/gin</code>，你可以手动将该依赖包下载下来放置到<code>GOPATH</code>下面，我们这里为了使用<code>govendor</code>来进行管理，当然你可以使用其他的包管理工具，比如：dep、glide 等等。在<code>github.com/cnych/goappk8s</code>目录下面执行下面的操作：</p>

<pre><code class="language-shell">$ govendor init
$ govendor fetch github.com/gin-gonic/gin
</code></pre>

<blockquote>
<p>注意上面的包需要拉取一些墙外的包。</p>
</blockquote>

<p>然后我们切换到项目根目录，也就是<code>GOPATH</code>的路径，执行以下命令：</p>

<pre><code class="language-shell">$ go install github.com/cnych/goappk8s &amp;&amp; ./bin/goappk8s
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in &quot;debug&quot; mode. Switch to &quot;release&quot; mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /ping                     --&gt; main.main.func1 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8080
</code></pre>

<p>我们可以看到我们的<code>golang</code>服务已经运行起来了，然后我们浏览器中打开链接<a href="http://127.0.0.1:8080/ping">http://127.0.0.1:8080/ping</a>，可以看到页面上打印出了<code>PONG</code>，证明我们的服务已经正常启动了。</p>

<h2 id="docker">Docker</h2>

<p>根据上一篇文章 <a href="https://blog.qikqiak.com/post/multi-stage-build-for-docker">Docker 的多阶段构建</a>我们可以很容易的为上面的<code>golang</code>服务写一个<code>Dockerfile</code>文件：（与<strong>main.go</strong>同目录）</p>

<pre><code class="language-Dockerfile">FROM golang AS build-env
ADD . /go/src/app
WORKDIR /go/src/app
RUN go get -u -v github.com/kardianos/govendor
RUN govendor sync
RUN GOOS=linux GOARCH=386 go build -v -o /go/src/app/app-server

FROM alpine
RUN apk add -U tzdata
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime
COPY --from=build-env /go/src/app/app-server /usr/local/bin/app-server
EXPOSE 8080
CMD [ &quot;app-server&quot; ]
</code></pre>

<p>然后构建<code>Docker</code>镜像：</p>

<pre><code class="language-shell">$ docker build -t cnych/goappk8s:v1.0.0 .
.......(省略了)
Successfully built 00751f94d8a9
Successfully tagged cnych/goappk8s:v1.0.0
$ docker push cnych/goappk8s:v1.0.0
</code></pre>

<p>上面的操作可以将我们本地的镜像<code>cnych/goappk8s:v1.0.0</code>推送到公共的<code>dockerhub</code>上面去（当然前提是你得先注册了）。</p>

<p>到这里的话其实我们已经可以利用上面的镜像很容易的跑一个容器了，下面我们介绍下如何将服务部署到<code>kubernetes</code>上去。</p>

<h2 id="kubernetes">Kubernetes</h2>

<p>当然首先你得有一套可用的<code>kubernetes</code>环境，如果你对这部分还不熟悉的话，建议你可以先看下我们前面的<a href="https://blog.qikqiak.com/tags/kubernetes/">相关文章</a>。
在<code>Dockerfile</code>同目录下面新建文件用于描述<code>kubernetes</code>的部署方式：（<strong>k8s.yaml</strong>）</p>

<pre><code class="language-yaml">---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: goapp-deploy
  namespace: kube-apps
  labels:
    k8s-app: goappk8s
spec:
  replicas: 2
  revisionHistoryLimit: 10
  minReadySeconds: 5
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  template:
    metadata:
      labels:
        k8s-app: goappk8s
    spec:
      containers:
      - image: cnych/goappk8s:v1.0.0
        imagePullPolicy: Always
        name: goappk8s
        ports:
        - containerPort: 8080
          protocol: TCP
        resources:
          limits:
            cpu: 100m
            memory: 100Mi
          requests:
            cpu: 50m
            memory: 50Mi
        livenessProbe:
          tcpSocket:
            port: 8080
          initialDelaySeconds: 10
          timeoutSeconds: 3
        readinessProbe:
          httpGet:
            path: /ping
            port: 8080
          initialDelaySeconds: 10
          timeoutSeconds: 2

---
apiVersion: v1
kind: Service
metadata:
  name: goapp-svc
  namespace: kube-apps
  labels:
    k8s-app: goappk8s
spec:
  ports:
    - name: api
      port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    k8s-app: goappk8s

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: goapp-ingress
  namespace: kube-apps
spec:
  rules:
  - host: goappk8s.local
    http:
      paths:
      - path: /
        backend:
          serviceName: goapp-svc
          servicePort: api
</code></pre>

<p>上面的<code>k8s.yaml</code>文件中，我们定义了3类资源：<code>Deployment</code>、<code>Service</code>、<code>Ingress</code>，如果对<code>YAML</code>文件还不太了解的同学，可以查看前面的文章<a href="https://blog.qikqiak.com/post/use-yaml-create-kubernetes-deployment/">使用YAML 文件创建 Kubernetes Deployment</a>，其中我们设置了<code>replicas: 2</code>，表示我们会运行两个<code>POD</code>，下面还定义了<code>strategy</code>的滚动策略为<code>RollingUpdate</code>，<code>resources</code>区域定义了我们一个<code>POD</code>的资源限制，通过<code>livenessProbe</code>和<code>readinessProbe</code>设置了健康检查。然后我们用<code>kubectl</code>执行下面的命令：</p>

<pre><code class="language-shell">$ kubectl apply -f k8s.yaml
deployment &quot;goapp-deploy&quot; created
service &quot;goapp-svc&quot; created
ingress &quot;goapp-ingress&quot; created
</code></pre>

<p>我们可以看到上面定义的三种资源都创建成功了。然后查看资源状态：</p>

<pre><code class="language-shell">$ kubectl get deployments -n kube-apps |grep goapp
goapp-deploy     2         2         2            2           57s
$ kubectl get svc -n kube-apps |grep goapp
goapp-svc      ClusterIP   10.254.109.69    &lt;none&gt;        8080/TCP                         1m
$ kubectl get ingress -n kube-apps |grep goapp
goapp-ingress   goappk8s.local              80        1m
$ kubectl get pods -n kube-apps |grep goapp
goapp-deploy-84bb6979c-59qkl                             1/1       Running   0          2m
goapp-deploy-84bb6979c-mgg2r                             1/1       Running   0          2m
</code></pre>

<p>我们可以看到在<code>kubernetes</code>集群中已经有两个<code>POD</code>在运行了，然后我们可以本地<code>/etc/hosts</code>中定义上面<code>Ingress</code>中定义的域名：</p>

<pre><code class="language-bash">你的k8s集群节点IP goappk8s.local
</code></pre>

<p>然后我们在浏览器中访问链接<a href="http://goappk8s.local/ping">http://goappk8s.local/ping</a>，可以看到页面上已经打印出来<strong>PONG</strong>。
<img src="https://blog.qikqiak.com/img/posts/WX20180208-171124.png" alt="PONG" /></p>

<p>最后整理下代码，将我们的代码提交到<a href="https://github.com/cnych/goappk8s">github</a>去吧。</p>

<p>最后我们还可以结合<code>CI/CD</code>，增加持续集成功能，做到我们更新代码后，自动更新我们的<code>kubernetes</code>应用，这部分我们后面再单独进行说明。</p>

<p>最后不要忘记加微信好友哦~~~</p>

<p>扫描下面的二维码(或微信搜索<code>k8s技术圈</code>)关注我们的微信公众帐号，在微信公众帐号中回复 <strong>加群</strong> 即可加入到我们的 kubernetes 讨论群里面共同学习。
<img src="https://blog.qikqiak.com/img/posts/qrcode_for_gh_d6dd87b6ceb4_430.jpg" alt="qrcode" /></p>
      </article>

      
        

<h3>相关文章</h3>
<ul style="margin-bottom: 25px;">
    
    <li><a href="https://blog.qikqiak.com/post/multi-stage-build-for-docker/">Docker 的多阶段构建</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/install-docker-registry-harbor-in-kubernetes/">在kubernetes 集群上搭建docker 私有仓库Harbor</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/manual-install-high-available-kubernetes-cluster/">手动搭建高可用的kubernetes 集群</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/use-yaml-create-kubernetes-deployment/">使用YAML 文件创建 Kubernetes Deployment</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/how-to-use-podpreset-in-kubernetes/">kubernetes PodPreset 的使用</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/python-virtualenv-all-know/">Python 虚拟环境全知道</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/first-use-helm-on-kubernetes/">Kubernetes Helm 初体验</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/understand-kubernetes-configmap-and-secrets/">kubernetes ConfigMap 和 Secrets</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/add-authorization-for-kubernetes-dashboard/">为kubernetes dashboard访问用户添加权限控制</a></li>
    
    <li><a href="https://blog.qikqiak.com/post/alertmanager-of-prometheus-in-practice/">Prometheus报警AlertManager实战</a></li>
    
</ul>

      

      
      <ul class="pager blog-pager">
        
          <li class="previous">
            <a href="https://blog.qikqiak.com/post/multi-stage-build-for-docker/" data-toggle="tooltip" data-placement="top" title="Docker 的多阶段构建">&larr; Previous Post</a>
          </li>
        
        
          <li class="next">
            <a href="https://blog.qikqiak.com/post/understand-kubernetes-configmap-and-secrets/" data-toggle="tooltip" data-placement="top" title="kubernetes ConfigMap 和 Secrets">Next Post &rarr;</a>
          </li>
        
      </ul>
      

      

      
      <div id="git-comments"></div>
      <link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
      <script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>
      <script>
      var gitment = new Gitment({
        id: 'write-kubernets-golang-service-step-by-step',
        owner: 'cnych',
        repo: 'blog',
        oauth: {
          client_id: 'bdb76dbb2e9d0786e350',
          client_secret: 'b454b2a08013fd0e32013be7a63fa8fcb262b6c4',
        }
      })
      gitment.render('git-comments')
      </script>
      

    </div>
  </div>
</div>

    <footer>
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <ul class="list-inline text-center footer-links">
          
              <li>
                <a href="mailto:icnych@gmail.com" title="Email me">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-circle fa-stack-2x"></i>
                    <i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
                  </span>
                </a>
              </li>
          
              <li>
                <a href="https://github.com/cnych" title="GitHub">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-circle fa-stack-2x"></i>
                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                  </span>
                </a>
              </li>
          
              <li>
                <a href="https://weibo.com/cnych" title="微博">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-circle fa-stack-2x"></i>
                    <i class="fa fa-weibo fa-stack-1x fa-inverse"></i>
                  </span>
                </a>
              </li>
          
              <li>
                <a href="https://instagram.com/cnych" title="Instagram">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-circle fa-stack-2x"></i>
                    <i class="fa fa-instagram fa-stack-1x fa-inverse"></i>
                  </span>
                </a>
              </li>
          
          
          <li>
            <a href="https://blog.qikqiak.com/index.xml" title="RSS">
              <span class="fa-stack fa-lg">
                <i class="fa fa-circle fa-stack-2x"></i>
                <i class="fa fa-rss fa-stack-1x fa-inverse"></i>
              </span>
            </a>
          </li>
          
        </ul>
        <p class="credits copyright text-muted">
          

          &nbsp;&bull;&nbsp;
          2018

          
            &nbsp;&bull;&nbsp;
            <a href="https://blog.qikqiak.com/">阳明的博客</a>
          
        </p>
        
        <p class="credits theme-by text-muted">
          <a href="http://gohugo.io">Hugo v0.34</a> powered &nbsp;&bull;&nbsp; Theme by <a href="http://deanattali.com/beautiful-jekyll/">Beautiful Jekyll</a> adapted to <a href="https://github.com/halogenica/beautifulhugo">Beautiful Hugo</a>
          
        </p>
      </div>
    </div>
  </div>
</footer>

<script src="https://cdn.bootcss.com/KaTeX/0.7.1/katex.min.js"></script>
<script src="https://cdn.bootcss.com/KaTeX/0.7.1/contrib/auto-render.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://blog.qikqiak.com/js/main.min.js"></script>
<script src="https://blog.qikqiak.com/js/highlight.min.js"></script>
<script> hljs.initHighlightingOnLoad(); </script>
<script> renderMathInElement(document.body); </script>
<script src="https://blog.qikqiak.com/js/prism.js?t=123"></script>
<script src="https://cdn.bootcss.com/photoswipe/4.1.1/photoswipe.min.js"></script>
<script src="https://cdn.bootcss.com/photoswipe/4.1.1/photoswipe-ui-default.min.js"></script>
<script src="https://blog.qikqiak.com/js/load-photoswipe.min.js"></script>



<script async src="https://www.googletagmanager.com/gtag/js?id=UA-69668147-3"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-69668147-3');
</script>

  </body>
</html>

